#!/bin/bash

# 要释放的端口号列表
PORTS=(8501 7864 20000 20001 20002 21001 21002 21003 21004 21005 21006 21007 21008 21009 21010)  # 在这里添加你需要释放的端口号

# 遍历端口号列表
for PORT in "${PORTS[@]}"; do
    echo "Processing port: $PORT"
    
    # 查找占用端口的进程ID (PID)
    PIDS=$(sudo lsof -t -i:$PORT)
    
    if [ -z "$PIDS" ]; then
        echo "No process found on port $PORT"
    else
        # 杀死占用端口的进程
        for PID in $PIDS; do
            echo "Killing process $PID on port $PORT"
            sudo kill -9 $PID
        done
    fi

    echo "Done processing port: $PORT"
done

echo "All specified ports have been processed."